package com.usian.controller;

import com.usian.entity.PageResult;
import com.usian.entity.QueryPageBean;
import com.usian.pojo.Category;
import com.usian.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class CategoryController {
    @Autowired
    private CategoryService categoryService;



    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Category> a=categoryService.findAll();
        model.addAttribute("list",a);
        return "list";
    }

    /**
     * 添加用户
     */
    @RequestMapping("add")
    public String add(Category category){
        categoryService.add(category);
        return "redirect:/findAll";
    }

    @RequestMapping("del")
    public String del(Integer id){
        categoryService.del(id);
        return "redirect:/findAll";
    }

    @RequestMapping("update")
    public String update(Category category){
        categoryService.update(category);
        return "redirect:/findAll";
    }

    @RequestMapping("findById")
    public String findById(Model model,Integer id){
        Category category=categoryService.findById(id);
        model.addAttribute("c",category);
        return "update";
    }
}
